# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-get_process_mem
pkgver=0.2.7
_commit=2897a5a76dec655bdc4242ec75538fc7896395f1
pkgrel=2
pkgdesc='Get memory usage of a process in Ruby'
arch=(any)
url='https://github.com/zombocom/get_process_mem'
license=(MIT)
depends=(ruby-ffi)
makedepends=(git ruby-sys-proctable ruby-rake ruby-test-unit)
options=(!emptydirs)
source=(git+https://github.com/zombocom/get_process_mem.git#commit=$_commit)
sha256sums=('SKIP')

prepare() {
  cd get_process_mem
  sed -r -e 's|~>|>=|g' -i get_process_mem.gemspec
  sed -i '/Bundler.require/d' test/test_helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd get_process_mem
  gem build get_process_mem.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    get_process_mem-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd get_process_mem
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd get_process_mem
  cp -a tmp_install/* "$pkgdir"/
}
